<template>
  <div>
    <Card :bordered="false" dis-hover>
      <div style="display: flex;justify-content: space-between;">
        <Row :gutter="24" type="flex">
          <!-- 时间 -->
          <Col>
          <DatePicker type="daterange" clearable v-width="'100%'" format="yyyy-MM-dd" v-model="paramsdate"
            @on-change="askDatas" placeholder="请选择时间"></DatePicker>
          </Col>
          <!-- 状态 -->
          <Col>
          <Select v-model="params.status" clearable placeholder="请选择状态" @on-change="askDatas">
            <Option v-for="item in statusList" :value="item.value" :key="item.value">{{ item.label }}</Option>
          </Select>
          </Col>
        </Row>
        <!-- 分配任务按钮 -->
        <div>
          <Button type="success" @click="taskedit(0)">分配任务</Button>
        </div>
      </div>
      <div>
        <!-- 任务循环 -->
        <Row :gutter="24" type="flex">
          <Col span="8" v-for="(item, index) in datalist" :key="index" class="ivu-mt-16">
          <Card>
            <p slot="title">
              {{item.title}}
            </p>
            <div slot="extra">
              <a href="#" @click.prevent="setRemind(item)">
                提醒设置
              </a>
              <Divider type="vertical"></Divider>
              <a href="#" @click.prevent="seeDetail(item)">
                详细
              </a>
            </div>
            <div>
              <p>
                <span>任务时间：</span>
                <span>{{item.start_time_str}}~{{item.end_time_str}}</span>
              </p>
              <p class="ivu-pt-16">
                <span>任务人：</span>
                <Tooltip transfer  max-width="300">
                    <Tag
                        v-if="+index <= 3"
                        v-for="(items, index) in item.member_name_arr"
                        :key="index"
                        >
                        {{ items }}
                    </Tag><Tag v-if="item.member_name_arr.length>5">+{{item.member_name_arr.length-4}}</Tag>
                    <Tag
                        slot="content"
                        v-for="(items, index) in item.member_name_arr"
                        :key="index"
                        >{{ items }}</Tag
                    >
                </Tooltip>
                <!-- <Tag v-for="(items,index) in item.member_name_arr" :key="index">{{items}}</Tag> -->
              </p>
              <p class="ivu-pt-16">
                <span>回访人数：</span>
                <span>{{item.total_num}}人</span>
              </p>
              <Divider></Divider>
              <p>
                <Row type="flex" :gutter="8">
                  <Col>
                  <Badge v-if="+item.status === 0" status="error" :text="item.status_str" />
                  <Badge v-else-if="+item.status === 1" status="processing" :text="item.status_str" />
                  <Badge v-else-if="+item.status === 2" status="warning" :text="item.status_str" />
                  <Badge v-else-if="+item.status === 3" status="success" :text="item.status_str" />
                  <Badge v-else-if="+item.status === 4" status="default" :text="item.status_str" />
                  </Col>
                  <Col span="18">
                  <Progress class="ivu-ml-16" :percent="item.rate*1" />
                  </Col>
                </Row>
              </p>
            </div>
          </Card>
          </Col>
        </Row>
        <div class="ivu-mt ivu-text-center">
          <Page show-total show-elevator show-sizer :total="total" transfer :current.sync="params.page"
            :page-size="params.pageSize" :page-size-opts="pageOpts" @on-change="formSize"
            @on-page-size-change="formChangePage" />
        </div>
      </div>
    </Card>
    <!-- 提醒设置 -->
    <Modal v-model="modal" width="600" title="设置提醒" :mask-closable="false" @on-cancel="handleResets('modalForm')">
      <div>
        <Form ref="modalForm" :model="modalForm" :rules="ruleValidate">
          <FormItem label="钉钉token" prop="access_token" :label-width="100">
            <Input v-model="modalForm.access_token" placeholder="请输入钉钉token"></Input>
          </FormItem>
          <FormItem label="钉钉secret" :label-width="100">
            <Input v-model="modalForm.secret" placeholder="请输入钉钉secret"></Input>
          </FormItem>
          <FormItem v-for="(item, index) in modalForm.content" :label="`提醒内容${index*1+1}`" :label-width="100"
            :key="index">
            <Row :gutter="5">
              <Col span="6">
              <Select v-model="modalForm.content[index].status" placeholder="请选择状态" @on-change="statusselect(index, modalForm.content[index].status)">
                  <Option :disabled="disabledstatus.indexOf(item.value)>-1" v-if="item.value>0" v-for="item in statusList" :value="item.value" :key="item.value">{{ item.label }}</Option>
              </Select>
              </Col>
              <Col span="14">
              <Input v-model="modalForm.content[index].message" placeholder="请输入内容"></Input>
              </Col>
              <Col span="3">
              <Button @click="deleteOne(index)" v-if="index !==0">删除</Button>
              </Col>
            </Row>
          </FormItem>
          <FormItem :label-width="100">
            <Row>
                <Col span="12">
                    <Button type="dashed" :disabled="modalForm.content.length>=4" long @click="handleAdd" icon="md-add">添加提醒内容</Button>
                </Col>
            </Row>
        </FormItem>

        </Form>
      </div>
      <div slot="footer">
        <Button type="primary" @click="handleSubmits('modalForm')">保存</Button>
        <Button @click="handleResets('modalForm')" style="margin-left: 8px">取消</Button>
      </div>
    </Modal>
    <!-- 详情 -->
    <Drawer :mask-closable="false" width="850" v-model="drawer" title="详细">
      <div>
        <Row :gutter="5" justify="center" align="middle">
          <Col span="7">
          <div style="font-size: 16px;font-weight: 600">{{detailedlist.title}}</div>
          </Col>
          <Col span="11">
          <font color="#aaa">创建人：{{detailedlist.created_name}}</font>
          <font color="#aaa" class="ivu-ml-8">创建日期：{{detailedlist.created_at_str}}</font>
          </Col>
          <Col>
          <div style="text-align: right;">
            <ButtonGroup>
              <Button v-if="+detailedlist.is_close_op === 1" @click="handleRender(detailedlist.id)">关闭</Button>
              <Button v-if="+detailedlist.is_delete_op === 1" @click="confirm(detailedlist.id)">删除</Button>
            </ButtonGroup>
            <Button class="ivu-ml-8" v-if="+detailedlist.is_edit_op === 1" type="primary"
              @click="taskedit(detailedlist.id)">编辑</Button>
          </div>
          </Col>
        </Row>
      </div>
      <div class="ivu-mt-16">
        <Row>
          <Col span="12">
          <DescriptionList :col="1">
            <Description term="任务时间：">
              {{detailedlist.start_time}} ~ {{detailedlist.end_time}}
            </Description>
            <Description term="备注：" style="display:flex;">
              <Tooltip transfer v-if="detailedlist.remark" max-width="300" placement="bottom-end">
                  <span slot="content">{{detailedlist.remark}}</span>
                  <div style="width:300px;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">{{detailedlist.remark}}</div>
              </Tooltip>
            </Description>
            <Description term="筛选条件：" v-if="detailedlist.select_condition">
              <Tag v-if="detailedlist.select_condition.start_reg_time&&detailedlist.select_condition.end_reg_time">
                挂号时间：{{detailedlist.select_condition.start_reg_time}}~{{detailedlist.select_condition.end_reg_time}}
              </Tag>

              <Tag
                v-if="detailedlist.select_condition.start_last_callback_time&&detailedlist.select_condition.end_last_callback_time">
                上次回访时间：{{detailedlist.select_condition.start_last_callback_time}}~{{detailedlist.select_condition.end_last_callback_time}}
              </Tag>

              <Tag
                v-if="detailedlist.select_condition.start_missed_days&&detailedlist.select_condition.end_missed_days">
                未到天数：{{detailedlist.select_condition.start_missed_days}}~{{detailedlist.select_condition.end_missed_days}}
              </Tag>

              <Tag
                v-if="detailedlist.select_condition.start_surplus_num&&detailedlist.select_condition.end_missed_days">
                308剩余量：{{detailedlist.select_condition.start_surplus_num}}~{{detailedlist.select_condition.end_surplus_num}}
              </Tag>

              <Tag v-if="detailedlist.select_condition.outpatient_name_arr.length>0">
                就诊类型：{{detailedlist.select_condition.outpatient_name_arr.join(',')}}</Tag>

              <Tag v-if="detailedlist.select_condition.tag_name_arr.length>0">
                标签：{{detailedlist.select_condition.tag_name_arr.join(',')}}</Tag>
              <Tag v-if="detailedlist.select_condition.diseases_name_arr.length>0">
                病种：{{detailedlist.select_condition.diseases_name_arr.join(',')}}</Tag>
              <Tag>抗复发：{{+detailedlist.select_condition.is_anti_relapse===1?'是':"否"}}</Tag>
            </Description>
            <Description term="任务人：">
              <Tag v-for="(items,index) in detailedlist.member_name_arr" :key="index">{{items}}</Tag>
            </Description>
            <Description term="患者数：">
              <Tag>{{detailedlist.total_num}}</Tag>
            </Description>

          </DescriptionList>
          </Col>
          <Col span="12">
          <div style="text-align: right;position: relative;">
            <div>状态</div>
            <h2 class="ivu-mt-8">
              {{detailedlist.status_str}}
            </h2>
            <div class="ivu-mt-8" style="width: 60%;position: absolute;right:8px;">
              <Progress :percent="detailedlist.rate*1" />
            </div>
          </div>
          </Col>
        </Row>
      </div>
      <Divider />
      <Timeline>
        <TimelineItem v-for="item in detailedlist.operate_log_list" :key="item.id">
          <p class="time">{{item.created_at_str}}</p>
          <p class="content">{{item.content}}</p>
          <p class="consultant">
            <span>{{ item.profession_name }}</span>
            <span class="ivu-pl-8">{{ item.realname }}</span>
          </p>
        </TimelineItem>
      </Timeline>
    </Drawer>
    <!-- 分配 -->
    <Drawer :mask-closable="false" width="850" v-model="addDrawer" :title="edit?'编辑任务':'新增任务'"
      @on-close="handleReset('editparams')">
      <Form :model="editparams" ref="editparams" :label-width="120" :rules="ruleValidateTask">
        <FormItem label="任务名称：" prop="title">
          <Input v-model="editparams.title" placeholder="请输入任务名称，字数控制在10个字以内" maxlength="10" show-word-limit></Input>
        </FormItem>
        <FormItem label="备注：">
          <Input type="textarea" v-model="editparams.remark" placeholder="请输入备注"></Input>
        </FormItem>
        <Divider></Divider>
        <Row>
          <Col span="11">
          <FormItem label="挂号时间：">
            <DatePicker v-width="220" :options="optionss" type="daterange" @on-change="screentask" placeholder="挂号时间" v-model="editparams.reg_time"></DatePicker>
          </FormItem>
          </Col>
          <Col span="11">
          <FormItem label="末次回访时间：">
            <DatePicker v-width="220" :options="optionss" type="daterange" @on-change="screentask" placeholder="末次回访时间：" v-model="editparams.last_callback_time">
            </DatePicker>
          </FormItem>
          </Col>
        </Row>
        <Row>
          <Col span="11">
          <FormItem label="就诊类型：">
            <Select v-width="220" @on-change="screentask" multiple v-model="editparams.outpatient_type_idsarr" placeholder="就诊类型">
              <Option v-if="+item.status === 1" :value="item.id" v-for="item in editlist.outpatient_type_list"
                :key="item.id">{{item.name}}</Option>
            </Select>
          </FormItem>
          </Col>
          <Col span="11">
          <FormItem label="标签：">
            <Select v-width="220" @on-change="screentask" multiple v-model="editparams.tag_idsarr" placeholder="标签">
              <OptionGroup :label="item.name" v-for="item in editlist.tags_list" :key="item.id">
                <Option v-for="items in item.children" :value="items.id" :key="items.id">{{ items.name }}</Option>
              </OptionGroup>
            </Select>
          </FormItem>
          </Col>
          <Col span="11">
          <FormItem label="未到天数：">
            <div style="display: flex;">
              <InputNumber class="ivu-mr-16" placeholder="请输入" :max="9999" :min="0" :step="1" @on-change="inputblurmin(1)"
                v-model="editparams.start_missed_days" v-width="80" :formatter="ins"></InputNumber>
              <span class="ivu-mr-16">-</span>
              <InputNumber placeholder="请输入" :max="9999" :min="0" :step="1" @on-blur="inputblurmax(1)"
                v-model="editparams.end_missed_days" v-width="80" :formatter="ins"></InputNumber>
            </div>
          </FormItem>
          </Col>
          <Col span="11">
          <FormItem label="308剩余数：">
            <div style="display: flex;">
              <InputNumber class="ivu-mr-16" placeholder="请输入" :max="9999" :min="-999" :step="1"
                @on-change="inputblurmin(2)" v-model="editparams.start_surplus_num" v-width="80" :formatter="ins">
              </InputNumber>
              <span class="ivu-mr-16">-</span>
              <InputNumber v-model="editparams.end_surplus_num" v-width="80" placeholder="请输入" :max="9999" :min="-999"
                :step="1" @on-blur="inputblurmax(2)" :formatter="ins"></InputNumber>
            </div>
          </FormItem>
          </Col>
          <Col span="11">
          <FormItem label="病种：">
            <Select v-width="220" @on-change="screentask" multiple v-model="editparams.patient_diseases_idsarr" placeholder="病种">
              <Option v-if="+item.status === 1" :value="item.id" v-for="item in editlist.patient_diseases_list"
                :key="item.id">{{item.name}}</Option>
            </Select>
          </FormItem>
          </Col>
          <Col span="11">
          <FormItem label="抗复发标识：">
            <Checkbox @on-change="screentask" v-model="editparams.is_anti_relapsecheck"></Checkbox>
          </FormItem>
          </Col>
        </Row>
        <Divider></Divider>
        <FormItem label="患者数：">
          <span>{{editparams.total_num}}</span>
        </FormItem>
        <FormItem prop="time" label="任务时间：">
          <DatePicker v-width="220" type="daterange" :options="options" placeholder="任务时间" v-model="editparams.time"></DatePicker>
        </FormItem>
        <FormItem label="任务人：" prop="member_idsarr">
          <Select multiple v-model="editparams.member_idsarr" placeholder="任务人">
            <OptionGroup :label="item.name" v-for="item in editlist.member_list" :key="item.id">
              <Option v-for="items in item.children" :value="items.id" :key="items.id">{{ items.name }}</Option>
            </OptionGroup>
          </Select>
        </FormItem>
      </Form>
      <div class="demo-drawer-footer">
        <Button class="ivu-mr-8" @click="handleReset('editparams')">取消</Button>
        <Button type="primary" @click="handleSubmit('editparams')" :loading="loading">确定</Button>
      </div>
    </Drawer>
  </div>
</template>
<script>
  import {
    worktasklist,
    worktaskinfo,
    worktaskeditinfo,
    worktaskpatientres,
    worktaskremindinfo,
    worktaskcreate,
    worktaskupdate,
    worktaskclose,
    worktaskdelete,
    worktaskremind
  } from '@api/tasklist';
  export default {
    data() {
      const validatePass = (rule, value, callback) => {
        if (value[0] !== "" && value[1] !== "") {
          callback();
        } else {
          callback(new Error("请选择任务时间"));
        }
      };
      return {
		options: {
			disabledDate (date) {
				return date && date.valueOf() < Date.now() - 86400000;
			}
		},
		optionss: {
			disabledDate (date) {
				return date && date.valueOf() >= Date.now();
			}
		},
        drawer: false,
        loading: false,
        edit: false,
        beforeTimeOne: 0,
        beforeTimeTwo: 0,
        numRemainingOne: 0,
        numRemainingTwo: 0,
        addDrawer: false,
        paramsdate: [],
        params: {
          page: 1,
          pageSize: 6,
          start_time: '',
          end_time: '',
          status: "",
        },
        datalist: [],
        isDetail: {},
        disabledstatus:[1],
        modalForm: {
          id:'',
          access_token: "",
          secret:'',
          content: [
            {
              status:1,
              message:''
            },
          ]
        },
        ruleValidate: {
          access_token: {
            required: true, message: '请输入钉钉token', trigger: 'blur'
          },
          secret: {
            required: true, message: '请输入钉钉secret', trigger: 'blur'
          },
        },
        ruleValidateTask: {
          title: {
            required: true, message: '请输入任务名称', trigger: 'blur'
          },
          time: [
            // { required: true, message: '请选择任务时间', trigger: 'change' }
            { required: true,validator: validatePass, trigger: 'change' }

          ],
          member_idsarr: {
            required: true, message: '请选择任务人', trigger: 'change', type: 'array',
          },
        },
        modal: false,
        statusList: [
          { value: 0, label: '未开始' },
          { value: 1, label: '进行中' },
          { value: 2, label: '已延期' },
          { value: 3, label: '已完成' },
          { value: 4, label: '已关闭' },
        ],
        total: 0,
        pageOpts: [6, 9, 15, 30], // 分页每页数量
        editparams: {
          reg_time: ['', ''],
          start_reg_time: '',
          end_reg_time: '',
          last_callback_time: ['', ''],
          start_last_callback_time: '',
          end_last_callback_time: '',
          start_missed_days: null,
          end_missed_days: null,
          start_surplus_num: null,
          end_surplus_num: null,
          outpatient_type_idsarr: [],
          tag_idsarr: [],
          patient_diseases_idsarr: [],
          outpatient_type_ids: '',
          tag_ids: '',
          patient_diseases_ids: '',
          is_anti_relapsecheck: true,
          is_anti_relapse: '',
          title: '',
          remark: '',
          time: [],
          start_time: '',
          end_time: '',
          member_idsarr: [],
          member_ids: '',
          id: '',
          total_num: ''
        },
        detailedlist: {},
        editlist: {},
      }
    },
    computed: {
      lastOne() {
        return this.modalForm.content.length <= 1
      }
    },
    methods: {
		handleRender (id) {
			let value = ''
			this.$Modal.confirm({
				render: (h) => {
					return h('Input', {
						props: {
							value: value,
							autofocus: true,
							placeholder: '请输入关闭原因'
						},
						on: {
							input: (val) => {
								value = val
							},
						}
					})
				},
				onOk:()=>{
					worktaskclose({id,reason:value}).then(res=>{
						this.drawer = false
						this.askData()
					})
				}
			})
		},
		confirm (id) {
			this.$Modal.confirm({
				title: '删除提示',
				content: '<p>是否确认删除此条任务</p>',
				onOk: () => {
					worktaskdelete({id}).then(res=>{
						this.$Message.success('删除成功');
						this.drawer = false
						this.askData()
					})
				},
			});
    },
    statusselect(index, e){
      this.disabledstatus[index] = e
    },
    handleAdd () {
        this.modalForm.content.push({
          status:'',
          message:''
        });
    },
		initial() {
			this.askData()
		},
		askData() {
			this.params.start_time = this.paramsdate[0]
			this.params.end_time = this.paramsdate[1]
			worktasklist(this.params).then(res => {
        this.total = res.total
        this.datalist = res.list
			})
    },
    askDatas() {
      this.params.page = 1
      this.params.pageSize = 6
      this.askData();
    },
		/* @函数功能: 分页 */
		formSize(e) {
			this.params.page = e;
			this.askData();
		},
		/* @函数功能: 每页数量 */
		formChangePage(e) {
			this.params.pageSize = e;
			this.askData();
		},
		// 数字输入框为正整数
		ins(e) {
			return parseInt(e)
		},
		screentask() {
			let parpams = {
			start_reg_time: this.editparams.reg_time[0],
			end_reg_time: this.editparams.reg_time[1],
			start_last_callback_time: this.editparams.last_callback_time[0],
			end_last_callback_time: this.editparams.last_callback_time[1],
			start_missed_days: this.editparams.start_missed_days,
			end_missed_days: this.editparams.end_missed_days,
			start_surplus_num: this.editparams.start_surplus_num,
			end_surplus_num: this.editparams.end_surplus_num,
			outpatient_type_ids: this.editparams.outpatient_type_idsarr.join(','),
			tag_ids: this.editparams.tag_idsarr.join(','),
			patient_diseases_ids: this.editparams.patient_diseases_idsarr.join(','),
			is_anti_relapse: this.editparams.is_anti_relapsecheck ? 1 : 0,
			}
			worktaskpatientres(parpams).then(res => {
			this.editparams.total_num = res.total
			})
		},
		inputblurmin(num) {
			if (num === 1) {
			if (this.editparams.end_missed_days !== null) {
				if (this.editparams.start_missed_days > this.editparams.end_missed_days) {
				this.$Message.error('请输入合理的未访天数')
				this.editparams.start_missed_days = null
				} else {
				this.screentask()
				}
			}
			} else if (num === 2) {
			if (this.editparams.end_surplus_num !== null) {
				if (this.editparams.start_surplus_num > this.editparams.end_surplus_num) {
				this.$Message.error('请输入合理的308剩余数')
				this.editparams.start_surplus_num = null
				} else {
				this.screentask()
				}
			}
			}
		},
		inputblurmax(num) {
			if (num === 1) {
			if (this.editparams.start_missed_days !== null) {
				if (this.editparams.start_missed_days > this.editparams.end_missed_days) {
				this.$Message.error('请输入合理的未访天数')
				this.editparams.end_missed_days = null
				} else {
				this.screentask()
				}
			}
			} else if (num === 2) {
			if (this.editparams.start_surplus_num !== null) {
				if (this.editparams.start_surplus_num > this.editparams.end_surplus_num) {
				this.$Message.error('请输入合理的308剩余数')
				this.editparams.end_surplus_num = null
				} else {
				this.screentask()
				}
			}
			}
		},
		taskedit(id) {
			if (id === 0) this.edit = false
			else this.edit = true
			worktaskeditinfo({ id }).then(res => {
			this.editlist = res.condition
			this.editparams.id = res.id
			this.editparams.title = res.title
			this.editparams.remark = res.remark
			this.editparams.reg_time = [res.select_condition.start_reg_time, res.select_condition.end_reg_time]
			this.editparams.last_callback_time = [res.select_condition.start_last_callback_time, res.select_condition.end_last_callback_time]
			this.editparams.outpatient_type_idsarr = res.select_condition.outpatient_type_ids
			this.editparams.tag_idsarr = res.select_condition.tag_ids
			this.editparams.start_missed_days = res.select_condition.start_missed_days === '' ? null : res.select_condition.start_missed_days * 1
			this.editparams.end_missed_days = res.select_condition.end_missed_days === '' ? null : res.select_condition.end_missed_days * 1
			this.editparams.start_surplus_num = res.select_condition.start_surplus_num === '' ? null : res.select_condition.start_surplus_num * 1
			this.editparams.end_surplus_num = res.select_condition.end_surplus_num === '' ? null : res.select_condition.end_surplus_num * 1
			this.editparams.patient_diseases_idsarr = res.select_condition.patient_diseases_ids
			this.editparams.is_anti_relapsecheck = +res.select_condition.is_anti_relapse === 1
			this.editparams.total_num = res.total_num
			this.editparams.time = [res.start_time, res.end_time]
			this.editparams.member_idsarr = res.member_id_arr
			this.addDrawer = true
			})
		},
		// 新增编辑任务
		handleSubmit(name) {
			this.$refs[name].validate((valid) => {
			if (valid) {
					let params = {
						id: this.editparams.id,
						start_reg_time: this.editparams.reg_time[0],
						end_reg_time: this.editparams.reg_time[1],
						start_last_callback_time: this.editparams.last_callback_time[0],
						end_last_callback_time: this.editparams.last_callback_time[1],
						start_missed_days: this.editparams.start_missed_days===null?'':this.editparams.start_missed_days+'',
						end_missed_days: this.editparams.end_missed_days===null?'':this.editparams.end_missed_days+'',
						start_surplus_num: this.editparams.start_surplus_num===null?'':this.editparams.start_surplus_num+'',
						end_surplus_num: this.editparams.end_surplus_num===null?'':this.editparams.end_surplus_num+'',
						outpatient_type_ids: this.editparams.outpatient_type_idsarr.join(','),
						tag_ids: this.editparams.tag_idsarr.join(','),
						patient_diseases_ids: this.editparams.patient_diseases_idsarr.join(','),
						is_anti_relapse: this.editparams.is_anti_relapsecheck?1:0,
						title: this.editparams.title,
						remark: this.editparams.remark,
						start_time: this.editparams.time[0],
						end_time: this.editparams.time[1],
						member_ids: this.editparams.member_idsarr.join(','),
					}
				if (!params.start_reg_time&&!params.start_last_callback_time&&!params.start_missed_days&&!params.end_missed_days&&!params.start_surplus_num&&!params.end_surplus_num&&!params.patient_diseases_ids&&!params.tag_ids&&!params.outpatient_type_ids) {
					this.$Message.error('请筛选任务')
					return
				}
				if (this.editparams.total_num>0) {
          this.loading = true
					if (this.edit) {
						worktaskupdate(params).then(res=>{
              this.addDrawer = false
              this.loading = false
              this.$refs[name].resetFields();
              this.askData()
              this.seeDetail(params)
						}).catch(()=>{
              this.loading = false
            })
					} else {
						params.id = ''
						worktaskcreate(params).then(res=>{
              this.addDrawer = false
              this.loading = false
              this.$refs[name].resetFields();
							this.askData()
						}).catch(()=>{
              this.loading = false
            })
					}
				} else {
					this.$Message.error('患者数不能为空')
				}
			}
			})
		},
		// 取消新增编辑任务
		handleReset(name) {
			this.$refs[name].resetFields();
			this.modal = false
			this.addDrawer = false
		},
		// 设置提醒确定
		handleSubmits(){
      let params = {
        id: this.modalForm.id,
        access_token: this.modalForm.access_token,
        secret: this.modalForm.secret,
        content: '',
      }
      let list = {};
      for(let index in this.disabledstatus) {
        if (this.disabledstatus[index]) {
            list[this.disabledstatus[index]] = this.modalForm.content[index].message;
        }
      }
      params.content = JSON.stringify(list)
      worktaskremind(params).then(res=>{
        this.modal = false
        this.askData()
      })
    },
		// 设置提醒重置
		handleResets(name) {
			this.$refs[name].resetFields();
			this.modal = false
			this.addDrawer = false
		},
		// 设置提醒
		setRemind(row) {
      worktaskremindinfo({ id: row.id }).then(res => {
        this.modalForm.id = row.id
        this.modalForm.access_token = res.access_token
        this.modalForm.secret = res.secret
        this.modalForm.content = []
        this.disabledstatus = []
        if (res.content.length === 0) {
          this.modalForm.content = [{
              status:1,
              message:''
          }]
          this.disabledstatus = [1]
        } else {
          let list = Object.keys(res.content)
          for (let item of list) {
            this.modalForm.content.push({
                status:item*1,
                message:res.content[item]
            })
            this.disabledstatus.push(item*1)
          }
        }
          this.modal = true
      })
		},
		// 打开详细
		seeDetail(row) {
			worktaskinfo({ id: row.id }).then(res => {
				this.detailedlist = res
				this.drawer = true
			})
		},
		deleteOne(index) {
      this.modalForm.content.splice(index, 1)
      this.disabledstatus.splice(index, 1)
		}
		},
		watch: {
			editparams: {
				handler(value) {
				},
				deep: true
			}
		},
		mounted() {
			this.initial()
		}
  }
</script>
<style lang="less" scoped>
  .pStyle {
    font-size: 16px;
    color: 'rgba(0,0,0,0.85)';
    line-height: 24px;
    display: block;
    margin-bottom: 16px;
  }

  .demo-drawer-footer {
    width: 100%;
    position: absolute;
    bottom: 0;
    left: 0;
    border-top: 1px solid #e8e8e8;
    padding: 10px 16px;
    text-align: right;
    background: #fff;
  }

  .consultant {
    color: #9ea7b4;
  }
  /deep/.ivu-tooltip-inner{
    max-width: none!important;
  }
</style>